package friend

import (
	"context"

	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/svc"
	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/types"
	"gitee.com/gao-deguang/easy-chat/apps/social/rpc/social"
	"gitee.com/gao-deguang/easy-chat/pkg/ctxdata"

	"github.com/zeromicro/go-zero/core/logx"
)

type FriendPutInListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 好友申请列表
func NewFriendPutInListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FriendPutInListLogic {
	return &FriendPutInListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FriendPutInListLogic) FriendPutInList(req *types.FriendPutInListReq) (resp *types.FriendPutInListResp, err error) {
	// todo: add your logic here and delete this line

	requests, err := l.svcCtx.Social.FriendPutInList(l.ctx, &social.FriendPutInListReq{
		UserId: ctxdata.GetUID(l.ctx),
	})
	if err != nil {
		return nil, err
	}

	if len(requests.List) == 0 {
		return &types.FriendPutInListResp{}, nil
	}

	respList := make([]*types.FriendRequests, len(requests.List))
	for _, v := range requests.List {

		fq := &types.FriendRequests{
			Id:           int64(v.Id),
			UserId:       v.UserId,
			ReqId:        v.ReqUid,
			ReqMsg:       v.ReqMsg,
			ReqTime:      v.ReqTime,
			HandleResult: int(v.HandleResult),
		}
		respList = append(respList, fq)
	}
	return &types.FriendPutInListResp{
		List: respList,
	}, nil
}
